$(function(){
    //加载轮播图
    loadCarousel();
    //加载服务信息
    loadService();
    //加载员工信息
    loadStaff();
    //加载新闻信息
    loadNews();
    //加载动态信息
    loadDynamic();
    //加载活动信息
    loadActivity();
})
//加载轮播图
function loadCarousel(){
    $.ajax({
        url : '/back/queryAllCarouselByPage',
        type : 'post',
        dataType : 'json'
    }).done(function(data){
        if(data){
            $('#fh5co-hero ul.slides').empty();
            for(var i=0;i<data.length;i++){
                var liHtml='<li style="background-image: url('+data[i].picture+');">'+
                                '<div class="overlay-gradient"></div>'+
                                '<div class="container">'+
                                    '<div class="row">'+
                                        '<div class="col-md-8 col-md-offset-2 text-center slider-text">'+
                                            '<div class="slider-text-inner">'+
                                                '<h1>'+data[i].title+'</h1>'+
                                                '<p><a class="btn btn-primary btn-lg" href="#">Start Learning Now!</a></p>'+
                                            '</div>'+
                                        '</div>'+
                                    '</div>'+
                                '</div>'+
                            '</li>';
                $('#fh5co-hero ul.slides').append(liHtml);
            }
            $('#fh5co-hero .flexslider').flexslider({
                animation: "slide",

                easing: "swing",
                direction: "vertical",

                slideshowSpeed: 5000,
                directionNav: true,
                start: function(){
                    setTimeout(function(){
                        $('.slider-text').removeClass('animated fadeInUp');
                        $('.flex-active-slide').find('.slider-text').addClass('animated fadeInUp');
                    }, 500);
                },
                before: function(){
                    setTimeout(function(){
                        $('.slider-text').removeClass('animated fadeInUp');
                        $('.flex-active-slide').find('.slider-text').addClass('animated fadeInUp');
                    }, 500);
                }

            });
        }
    })
}
//加载服务信息
function loadService(){
    $.ajax({
        url : '/back/queryAllServiceByPage',
        type : 'post',
        dataType : 'json'
    }).done(function(data){
        if(data){
            $('#fh5co-course .service').empty();
            for(var i=0;i<data.length;i++){
                var ser_html='<div class="col-md-6 animate-box fadeInUp animated-fast">'+
                                '<div class="course">'+
                                    '<a href="#" class="course-img" style="background-image: url('+data[i].picture+');">'+
                                    '</a>'+
                                    '<div class="desc">'+
                                        '<h3><a href="#">'+data[i].title+'</a></h3>'+
                                        '<p>'+data[i].description+'</p>'+
                                        '<span><a href="#" class="btn btn-primary btn-sm btn-course">Take A Course</a></span>'+
                                    '</div>'+
                                '</div>'+
                            '</div>';
                $('#fh5co-course .service').append(ser_html);
            }
        }
    })

}
//加载员工
function loadStaff(){
    $.ajax({
        url : '/back/queryAllStaffByPage',
        type : 'post',
        dataType : 'json'
    }).done(function(data){
        if(data){
            $('.owl-carousel-fullwidth').empty();
            //$('.owl-carousel-fullwidth .owl-dots').empty();
            for(var i=0;i<data.length;i++){
            //<div class="owl-item cloned" style="width: 975px; margin-right: 0px;">
                var item='' +
                    '<div class="item">'+
                    '<div class="testimony-slide text-center">'+
                    '<div class="user" style="background-image: url('+data[i].picture+');"></div>'+
                    '<span>'+data[i].name+'<br><small>'+data[i].position+'</small></span>'+
                    '<blockquote>'+
                    '<p>'+data[i].description+'</p>'+
                    '</blockquote>'+
                    '</div>'+
                    //'</div>'+
                    '</div>';
                $('.owl-carousel-fullwidth').append(item);
                //var owl_dot='<div class="owl-dot"><span></span></div>';
                //$('.owl-carousel-fullwidth .owl-dots').append(owl_dot);
                if(i==0){
                //    $('.owl-carousel-fullwidth .owl-dots .owl-dot').addClass('active');
                   $('.owl-carousel-fullwidth .item .testimony-slide').addClass('active');
                }
            }
            var owl = $('.owl-carousel-fullwidth');
            owl.owlCarousel({
                items: 1,
                loop: true,
                autoplay: true,
                margin: 0,
                nav: false,
                dots: true,
                smartSpeed: 800,
                autoHeight: true
            });

        }
    })
}
//加载新闻
function loadNews(){
    $.ajax({
        url : '/back/queryAllNewsByPage',
        type : 'post',
        dataType : 'json'
    }).done(function(data){
        if(data){
            $('#fh5co-blog .news').empty();
            for(var i=0;i<data.length;i++){
                var divHtml='<div class="col-md-4 animate-box fadeInUp animated-fast">'+
                                '<div class="fh5co-event">'+
                                    '<div class="date text-center"><span>15<br>Mar.</span></div>'+
                                    '<h3><a href="#">'+data[i].title+'</a></h3>'+
                                    '<p class="text-ellipsis">'+data[i].description+'</p>'+
                                    '<p><a href="#">Read More</a></p>'
                                '</div>'+
                            '</div>';
                $('#fh5co-blog .row-padded-mb').append(divHtml);
            }
        }
    })
}
//加载动态信息
function loadDynamic(){
    $.ajax({
        url : '/back/queryAllDynamicByPage',
        type : 'post',
        dataType : 'json'
    }).done(function(data){
        if(data){
            $('#fh5co-blog .dynamic').empty();
            for(var i=0;i<data.length;i++){
                var dy_html='<div class="col-lg-4 col-md-4">'+
                                '<div class="fh5co-blog animate-box fadeInUp animated-fast">'+
                                    '<a href="#" class="blog-img-holder" style="background-image: url('+data[i].picture+');"></a>'+
                                    '<div class="blog-text">'+
                                        '<h3><a href="#">'+data[i].title+'</a></h3>'+
                                        '<span class="posted_on">'+data[i].dynDate+'</span>'+
                                        '<p style="display: -webkit-box; -webkit-box-orient: vertical;  -webkit-line-clamp: 4;  overflow: hidden;  text-overflow: ellipsis;">'+data[i].description+'</p>'+
                                    '</div> '+
                                '</div>'+
                            '</div>';
                $('#fh5co-blog .dynamic').append(dy_html);
            }

        }
    })
}
//加载活动信息
function loadActivity(){
    $.ajax({
        url : '/back/queryAllActivityByPage',
        type : 'post',
        dataType : 'json'
    }).done(function(data){
        if(data){
            $('#fh5co-gallery .activity').empty();
            for(var i=0;i<data.length;i++){
                var act_html='<div class="col-md-3 col-padded">'+
                    '<a href="#" class="gallery" style="background-image: url('+data[i].picture+');"></a>'+
                    '</div>';
                $('#fh5co-gallery .activity').append(act_html);
            }
        }
    })
}